package com.spzx.order.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.order.api.RemoteOrderService;
import com.spzx.order.domain.OrderInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RemoteOrderFallbackFactory implements FallbackFactory<RemoteOrderService> {
    @Override
    public RemoteOrderService create(Throwable cause) {
        log.error("远程访问spzx-order服务失败: {}" , ExceptionUtils.getStackTrace(cause));
        return new RemoteOrderService() {

            @Override
            public R<OrderInfo> getOrderByOrderNo(String orderNo) {
                log.error("查询订单失败，订单编号:{}",orderNo);
                return R.fail("查询订单数据失败");
            }
        };
    }
}
